<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="f"%>
<%@page import="com.kh.pajx.sop.util.common.FormatDate"%>
<%
	String path = request.getContextPath();
	String temp_str = FormatDate.getUseDate(new Date());
%>
		<script language="javascript" type="text/javascript" src="${pageContext.request.contextPath}/script/js/jquery.PrintArea.js"></script>
<script type="text/javascript">
function showTr(sid,state){
	var tr ="";
	var whichEl = document.getElementById("tr" + sid);
	var datalist=$("#foreign"+sid);
	datalist.empty();
	if (whichEl.style.display == "none") {
		if(state==1){
			var data={"foreign.appBillCode":sid};
			var url="foreign_findForeignList.action";
	$.post(url,data,function(message){
		var list=message;
		var str=list.split(";");
		for ( var i = 0; i < str.length-1; i++) {
			tr+="<tr>";
			var str1=str[i].split(",");
			for ( var j = 2; j< str1.length-1; j++) {
				if(j==10||j==12||j==14||j==16){
					tr+="<td><span style='color:red'>"
						 +str1[j]
						  +"</span></td>";
				}else{
				tr+="<td>"
				 +str1[j]
				  +"</span></td>";
			  }
			}
			tr+="</tr>";
		}
		   datalist.append(tr);
		   whichEl.style.display = "";
		   initRemoveAllNode(sid);
	      })
		}else{
			var data={"areaManger.appBillCode":sid};
			var url="foreign_findAreaMangerList.action";
			$.post(url,data,function(message){
				var list=message;
				var str=list.split(";");
				for ( var i = 0; i < str.length-1; i++) {
					tr+="<tr>";
					var str1=str[i].split(",");
					for ( var j = 2; j< str1.length-1; j++) {
						if(j==11){
							tr+="<td><span style='color:red'>"
								 +str1[j]
								  +"</span></td>";
						}else{
						tr+="<td>"
						 +str1[j]
						  +"</span></td>";
					  }
					}
					tr+="</tr>";
				}
				datalist.append(tr);
				whichEl.style.display = "";
				initRemoveAllNode(sid);
			})
		}
	}else{
		 initRemoveNode(sid);
	}
}
function  initRemoveNode(sid){
	var whichEl = document.getElementById("tr" + sid);
	whichEl.style.display = "none";
}
function  initRemoveAllNode(sid){
	　var whichEl=document.getElementsByName("tr_code");
			for(var i=0;i<whichEl.length;i++){
				if(whichEl[i].value!=sid){
					var tr= document.getElementById("tr" + whichEl[i].value);
					if(tr.style.display = "none"){
					}else{
				   tr.style.display = "none";
				     $("#tr" + whichEl[i].value).empty();
					}
				}
			}
	 };
	 function print(){
		 var rel=$("tr.selected").attr('rel');
		if(typeof(rel) != "undefined"){
			var sid=rel.split(",")[0];
			var feesum=rel.split(",")[1];
			var appDate=rel.split(",")[2];
			var state=rel.split(",")[3];
			var billState=rel.split(",")[4];
			if(billState==2){
		      var s=sid+";"+feesum+";"+appDate.substring(0,10);
			   var len=s.length;
			   var rs="";
			   for(var i=0;i<len;i++){
			          var k=s.substring(i,i+1);
			          rs+= (i==0?"":",")+s.charCodeAt(i);
			   }
			   if(state==1)
			   var url = "<%=path%>/print/foreign_print.jsp?sid="+rs+"&timestamp="+ new Date().getTime();
			   else
			    var url = "<%=path%>/print/areaManger_print.jsp?sid="+rs+"&timestamp="+ new Date().getTime(); 
			  window.open(url,"单据打印","_blank,resizable=yes,location=yes");
			}else if(billState==3){
				alertMsg.info("已签批,禁止单据打印");
			}else{
				alertMsg.info("没审批,禁止单据打印");
			}
		}else{
			alertMsg.info("请选择一条记录");
		}
	 };
	 function printForeign(){
		 var rel=$("#tableforeign tr.selected").attr('rel');
			if(typeof(rel) != "undefined"){
				var sid=rel.split(",")[0];
				var feesum=rel.split(",")[1];
				var appDate=rel.split(",")[2];
				var state=rel.split(",")[3];
				var billState=rel.split(",")[4];
				if(billState==2){
	      var s=sid+";"+feesum+";"+appDate.substring(0,10);
		   var len=s.length;
		   var rs="";
		   for(var i=0;i<len;i++){
		          var k=s.substring(i,i+1);
		          rs+= (i==0?"":",")+s.charCodeAt(i);
		   }
		   if(state==1)
		   var url = "<%=path%>/print/foreign_print_foreign.jsp?sid="+rs+"&timestamp="+ new Date().getTime();
		   else
		    var url = "<%=path%>/print/areaManger_print_foreign.jsp?sid="+rs+"&timestamp="+ new Date().getTime(); 
		  window.open(url,"单据打印","_blank,resizable=yes,location=yes");
				}else if(billState==3){
					alertMsg.info("已签批,禁止单据打印");
				}else{
					alertMsg.info("没审批,禁止单据打印");
				}
			}else{
				alertMsg.info("请选择一条记录");
			}
};
	 function deleteForeign() {
		 var deleteTr=$("tr.selected").attr('deleteTr');
		 if(typeof(deleteTr) != "undefined"){
				var id=deleteTr.split(",")[0];
				var code=deleteTr.split(",")[1];
				var state=deleteTr.split(",")[2];
				var billState=deleteTr.split(",")[3];
				if(billState==1){
		 alertMsg.confirm("确定要撤销吗？", {
				okCall : function() {
			if(state==1){
			var data = {
					"model.uuid":id,
					"foreign.appBillCode":code
			};
			var url = "foreign_deleteForeign.action";
			}else{
				var data = {
						"model.uuid":id,
						"areaManger.appBillCode":code
				};
				var url = "foreign_deleteAreaManger.action";
			}
			 $.ajax({ 
				  url: url, 
				  type:"post",
				  data :data,
				  dataType:"json",
				  success: function(message){
					  navTabAjaxDone(message);
			      }});
				}})
				}else{
					alertMsg.info("已审批,禁止撤销");
				}
		 }else{
				alertMsg.info("请选择一条记录");
			}
		};
</script>
<form id="pagerForm" method="post" action="foreign_foreignList.action">
	<input type="hidden" name="pageNum" value="${currentPage}" />
	<input type="hidden" name="numPerPage" value="${numPerPage}" />
	</form>
<div class="pageContent">
	<div class="panelBar">
		<ul class="toolBar">
			<li><a class="delete" href="javascript:void(0)" onclick="deleteForeign()"><span>撤销</span></a></li>
			<li class="line">line</li>
			<li><a class="edit"    href="javascript:void(0)" onclick="print()"><span>对内打印 </span></a></li>
			<li><a class="icon" href="javascript:void(0)" onclick="printForeign()"><span>对外打印 </span></a></li> 
		</ul>             
	</div>
			<table class="list" width="100%" layoutH="70" id="tableforeign">
				<thead>
					<tr>
						<th>申请单号</th>
						<th>申请类型</th>
						<th>申请人</th>
						<th>申请金额</th>
						<th>申请日期</th>
						<th>审批人</th>
						<th>审批日期</th>
						<th>审批金额</th>
						<th>签批人</th>
						<th>签批日期</th>
						<th>状态</th>
					</tr>
				</thead>

				<tbody>
					<c:forEach items="${recordList}" var="fb" varStatus="countStatus">
						<tr id="row${fb.uuid}" rel="${fb.appBillCode},${fb.chkMoney},${appDate},${fb.appType},${fb.billState}" deleteTr="${fb.uuid},${fb.appBillCode},${fb.appType},${fb.billState}">
							<td ><a href="javascript:void(0);" onclick="showTr('${fb.appBillCode}','${fb.appType}')">${fb.appBillCode}</a></td>
							<td>
							<c:if test="${fb.appType==1}">对外结算</c:if>
							<c:if test="${fb.appType==2}">行业经理</c:if>
							</td>
							<td>
							 <script>
							 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
							 var data={saleId:'${fb.appPerson}'};
								$.post(url,data,function(message){
									var msg=message;
									$("#foreignList_appperson_"+${countStatus.count}).text(msg);
								})
							 </script>
							 <span id="foreignList_appperson_${countStatus.count}"></span>
							</td>
							<td>${fb.appSumFee}</td>
						<td>
						<f:parseDate value="${fb.appDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm"  />
						<f:parseDate value="${fb.appDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm"  var ="appDate"/>
						</td>
						<td>
						<c:if test="${!empty fb.chkPerson}">
						<script>
							 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
							 var data={saleId:'${fb.chkPerson}'};
								$.post(url,data,function(message){
									var msg=message;
									$("#foreignList_checkperson_"+${countStatus.count}).text(msg);
								})
							 </script>
							 <span id="foreignList_checkperson_${countStatus.count}"></span>
							 </c:if>
						</td>
						<td><f:parseDate value="${fb.chkDate}"
									pattern="yyyyMMddHHmm" var="test" /> <f:formatDate
									value="${test}" pattern="yyyy-MM-dd HH:mm" />
						</td>
						<td>
						${fb.chkMoney}
						</td>
						<td>
						<c:if test="${!empty fb.payPerson}">
						<script>
							 var url="foreign_findUser.action?timestamp="+ new Date().getTime();
							 var data={saleId:'${fb.payPerson}'};
								$.post(url,data,function(message){
									var msg=message;
									$("#payMan"+${countStatus.count}).text(msg);
								})
							 </script>
							 <span id="payMan${countStatus.count}"></span>
							 </c:if>
						</td>
						<td><f:parseDate value="${fb.payDate}"
									pattern="yyyyMMddHHmm" var="pay" /> <f:formatDate
									value="${pay}" pattern="yyyy-MM-dd HH:mm" />
						</td>
						<td>
						<c:if test="${fb.billState==2}">
						已审批/未签批
						</c:if>
						<c:if test="${fb.billState==3}">
						已审批/已签批
						</c:if>
						<c:if test="${fb.billState==1||fb.billState==null}">
							未审批/未签批
						</c:if>
						<input name="tr_code"  value="${fb.appBillCode}"  type="hidden"/>
						</td>
						</tr>
                       <tr  id='tr${fb.appBillCode}' style="display: none" >
                       <td colspan="13">
                       <table id='table1' width="100%" class="list">
                       <thead>
                       <c:if test="${fb.appType==1}">
                        <tr >
                       <th rowspan="2">学校名称</th>
                       <th rowspan="2">结算日期</th>
						<th rowspan="2">总人数</th>
						<th colspan="4" style="text-align:center">有效用户数</th>
						<th colspan="2" style="text-align:center">客户经理结算</th>
						<th colspan="2" style="text-align:center">学校现金返还</th>
						<th colspan="2" style="text-align:center">学校话费返还</th>
						<th colspan="2" style="text-align:center">管理员费用</th>
						<th rowspan="2">备注</th>
                       </tr>
                       <tr>
                       	<th>本期</th>
                       	<th>上期</th>
                       	<th>新增</th>
                       	<th>开通率</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	</tr>
                       	</c:if>
                       	 <c:if test="${fb.appType==2}">
                        <tr >
                       <th rowspan="2">地区名称</th>
                       <th rowspan="2">结算日期</th>
                       <th rowspan="2">学校数量</th>
						<th rowspan="2">总人数</th>
						<th colspan="4" style="text-align:center">有效用户数</th>
						<th colspan="2" style="text-align:center">行业经理结算</th>
						<th rowspan="2">备注</th>
                       </tr>
                       <tr>
                       	<th>本期</th>
                       	<th>上期</th>
                       	<th>新增</th>
                       	<th>开通率</th>
                       	<th>申请金额</th>
                       	<th>批复金额</th>
                       	</tr>
                       	</c:if>
                       </thead>
				      <tbody id="foreign${fb.appBillCode}">
				      </tbody>
                       </table>
                       </td>
                       </tr>
					</c:forEach>
				</tbody>
			</table></div>
<%@ include file="/WEB-INF/jsp/public/panelBar.jsp"%>